package ReSofting.it.GoldDirector.Helpers;


import ReSofting.it.GoldDirector.Interfaces.IInputBoxDelegate;
import ReSofting.it.GoldDirector.Model.InputData;
import android.R;
import android.app.AlertDialog;
import android.app.Application;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Editable;
import android.text.GetChars;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

	public class InputBoxNewOrder {
		

		static AlertDialog.Builder alert = null ;
		
		IInputBoxDelegate<InputData> listener;
				
	  public InputBoxNewOrder(IInputBoxDelegate<InputData> listener) {
	        this.listener = listener;
	    }
		
		
		public void showInputBox(final Context pContext, String pTitle, final String pToken)
		{
			AlertDialog.Builder alert = new AlertDialog.Builder(pContext);

			LayoutInflater inflater = (LayoutInflater) pContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			final View layout = inflater.inflate(ReSofting.it.GoldDirector.R.layout.inputbox_neworder,null );
						
			alert.setTitle(pTitle)
		    //.setMessage(pMessage)
		    .setView(layout)
		    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
		        public void onClick(DialogInterface dialog, int whichButton) {
		        		        			        	
		        	//prelevo i dati		        	
		        	EditText tavolo = (EditText) layout.findViewById(ReSofting.it.GoldDirector.R.id.text_IB_CheTavolo);
		        	EditText quanti  = (EditText) layout.findViewById(ReSofting.it.GoldDirector.R.id.text_IB_QuantiClienti);
		    		
		        	String val1 =  (String)tavolo.getText().toString().trim(); 
		        	String val2 =  (String)quanti.getText().toString().trim(); 
		            		          
	
		            if ((val1.length() > 0) && (val2.length()> 0)  ) 
		            {
		            	Toast.makeText(pContext, "not null " + (val1== "")
		            			+ (val2.length()) , Toast.LENGTH_SHORT).show();
						
		            	listener.onInputCallComplete(
		            		new InputData( val1, Integer.parseInt( val2), Integer.parseInt( val2) )  ,pToken);			            			            	
		            }	
		            else
		            	Toast.makeText(pContext, ReSofting.it.GoldDirector.R.string.DatiMancanti, Toast.LENGTH_SHORT).show();
					
		
		            
		        }
		    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
		        public void onClick(DialogInterface dialog, int whichButton) {
		        	listener.onInputCallComplete(null,pToken);
		            //notify;
		        }
		    });
					
			alert.show();
		    //.show();
					 
		
		}//fM
		
	}
